import request from '@/utils/request'

//获取微信授权 openId
export function getWxOpenId(appId, url,data) {
  let params = encodeURIComponent(JSON.stringify(data))
  // 拼接参数返回授权地址
  let toUrl = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' + appId + '&redirect_uri=' + url + '&response_type=code&scope=snsapi_base&state=' + params + '#wechat_redirect'
  return toUrl
}

export function getSign(data) {
  return request({
    url: '/wx/getWxPaySign',
    method: 'post',
    data
  })
}

//获取 appId
export function getWxAppId() {
  return request({
    url: '/wx/getWxAppId',
    method: 'get'
  })
}

//微信 code 换取 openId(只获取openId)
export function getWxBaseOpenId(code) {
  return request({
    url: '/wx/getBaseOpenId?code=' + code,
    method: 'get'
  })
}
